package com.tankgame.its381b;

/**
 *
 * @author Tank Team
 */
import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

public class TankSprite extends Sprite {

    private static final int WIDTH = 16;
    private static final int HEIGHT = 16;
    private boolean moveLeft = true;

    //create tank with tank.png and width, height
    public TankSprite() throws IOException {
        super(Image.createImage("/res/tank.png"), WIDTH, HEIGHT);
        //set reference pixel
        defineReferencePixel(getWidth() / 2, getHeight());
    }

    
    public void move() {
    	//sets sprite to next image frame
        nextFrame();
        //determines right or left movement of tank
        if(getX() <= 15) {
            moveLeft = false;
        } else if (getX() > 135) {
            moveLeft = true;
        }
        int xdelta = -1;

        if (moveLeft == false) {
            xdelta = 1;
        }
        int ydelta = 0;
        //move tank
        move(xdelta, ydelta);
    }
}
